import user from './user'

const api = Object.assign(user)

export default config => {
  // return Promise.resolve({
  //   status: 200,
  //   data: {
  //     code: 1,
  //     success: true,
  //     message: null,
  //     data: api[config.url],
  //   },
  // })
  let param = config.params || config.data
  if (param)
    param = JSON.parse(param)
  return new Promise((resolve, reject) => {
    const whites = ['/api/users/current', '/api/users/resources']
    const times = whites.includes(config.url) ? 10 : 1000
    const status = whites.includes(config.url) ? 200 : 200
    setTimeout(() => {
      resolve({
        status,
        data: {
          code: 1,
          success: true,
          message: '操作成功',
          data: api[config.url] && api[config.url](param),
        },
      })
    }, times)
  })
}
